﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Galaxy.AutoCAD.Options;
using AutoCADApp = Autodesk.AutoCAD.ApplicationServices;

namespace Galaxy.AutoCAD.Windows
{
    public partial class TextPropertyWindow : Form
    {
        public TextPropertyWindow()
        {
            InitializeComponent();
        }

        private void TextPropertyWindow_Load(object sender, EventArgs e)
        {
            foreach (string outString in CommonOptionTool.TextPropertyTextStyleNameSet)
            {
                comboBox1.Items.Add(outString);
            }
            if (comboBox1.Items.Count > 0)
            {
                if (comboBox1.Items.Contains("仿宋（工艺）"))
                {
                    comboBox1.SelectedItem = "仿宋（工艺）";
                }
                else
                {
                    comboBox1.SelectedItem = comboBox1.Items[0];
                }
            }
            textBox1.Text = "175";
            textBox2.Text = "0";
            textBox3.Text = "0";
        }

        private void comboBox1_Click(object sender, EventArgs e)
        {
            comboBox1.SelectAll();
        }

        private void textBox1_Click(object sender, EventArgs e)
        {
            textBox1.SelectAll();
        }

        private void textBox2_Click(object sender, EventArgs e)
        {
            textBox2.SelectAll();
        }

        private void textBox3_Click(object sender, EventArgs e)
        {
            textBox3.SelectAll();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            CommonOptionTool.TextPropertyPass = "1";
            if (comboBox1.SelectedItem == null)
            {
                AutoCADApp.Application.ShowAlertDialog("请选择有效值！");
                comboBox1.Focus();
                return;
            }
            else
            {
                CommonOptionTool.TextPropertyTextStyleName = comboBox1.Text;
            }
            double textHeight;
            if (double.TryParse(textBox1.Text, out textHeight))
            {
                CommonOptionTool.TextPropertyTextHeight = textHeight;
            }
            else
            {
                AutoCADApp.Application.ShowAlertDialog("请输入有效值！");
                textBox1.Focus();
                return;
            }
            double textPropertyXDeviantValue;
            if (double.TryParse(textBox2.Text, out textPropertyXDeviantValue))
            {
                CommonOptionTool.TextPropertyXDeviantValue = textPropertyXDeviantValue;
            }
            else
            {
                AutoCADApp.Application.ShowAlertDialog("请输入有效值！");
                textBox2.Focus();
                return;
            }
            double textPropertyYDeviantValue;
            if (double.TryParse(textBox3.Text, out textPropertyYDeviantValue))
            {
                CommonOptionTool.TextPropertyYDeviantValue = textPropertyYDeviantValue;
            }
            else
            {
                AutoCADApp.Application.ShowAlertDialog("请输入有效值！");
                textBox3.Focus();
                return;
            }
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            CommonOptionTool.TextPropertyPass = "0";
            CommonOptionTool.TextPropertyTextStyleName = "Standard";
            CommonOptionTool.TextPropertyTextHeight = 175;
            CommonOptionTool.TextPropertyXDeviantValue = 0.0;
            CommonOptionTool.TextPropertyYDeviantValue = 0.0;
            this.Close();
        }
    }
}
